import { GamePropData } from "../../Data/GamePropData";
import AspectRatioTool from "../../Tools/UiTool/AspectRatioTool";
import GamePanel from "../../Panel/GamePanel";
import { utils } from "../../../utils/CommonUtil";

export default class GamePropUi extends Laya.Script {
    /** 当前的道具信息*/
    public curData: GamePropData;

    /** 道具图片*/
    private propImage: fairygui.GLoader;

    private propImageTool: AspectRatioTool;

    /** 道具选中bg*/
    private selectBg: fairygui.GImage;

    private gamePanel: GamePanel;

    private parentComponent: fairygui.GComponent;

    public SetData(cpm: fairygui.GComponent, curData: GamePropData, gamePanel: GamePanel): void {
        this.parentComponent = cpm;
        this.gamePanel = gamePanel;
        this.curData = curData;
        this.InitComponent();
        this.RefreshUi();
    }

    private InitComponent(): void {
        this.propImage = this.parentComponent.getChild("propImage").asLoader;
        this.propImageTool = utils.CommonUtils.CustomAddComponent(this.owner,AspectRatioTool) as AspectRatioTool;
        this.selectBg = this.parentComponent.getChild("selectBg").asImage;
        this.parentComponent.onClick(this, this.OnClickThis);
    }

    /** 刷新ui*/
    private RefreshUi(): void {
        // window.gameFacade.AtlasMng.SetSpriteByName(this.propImage, "GameUIPanel", "BOSS");
        // console.log("this.propImage",this.propImage);
        this.propImageTool.SetSprite(this.propImage, this.curData.atlasName, this.curData.spriteName);
    }

    /** 设置 是否为选中状态图片*/
    public SetSelect(beSelected: boolean): void {
        this.selectBg.visible = beSelected;
    }

    /** 点击道具*/
    private OnClickThis() {
        this.gamePanel.ClickPropUi(this);
    }
}